//
//  UpdateUserInfoViewController.swift
//  d11
//
//  Created by rhonin on 2018/10/28.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
import SwiftyJSON
class UpdateUserInfoViewController: UpdateRootViewController {
    
    // 距离父视图顶部间距
    @IBOutlet weak var bottomViewTopConstraint: NSLayoutConstraint!
    
    @IBOutlet weak var buttonSingnin: UIButton!
    
    @IBOutlet weak var username: UITextField!
    @IBOutlet weak var viewCome: UIView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.viewCome.layer.borderColor = RGBAlpa(219,219,219,1).cgColor
        self.bottomViewTopConstraint.constant = kNavigationBarHeight
        self.title = "修改真实姓名"
        // 设置导航栏默认返回按钮
        self.leftButtonActionWithImg("icon_default_back")
        
        let layerGradient = CAGradientLayer()
        layerGradient.colors = [
            UIColor.init(red: 1, green: 0.78, blue: 0.45, alpha: 1).cgColor,
            UIColor.init(red: 0.99, green: 0.57, blue: 0.33, alpha: 1).cgColor
        ]
        layerGradient.frame = CGRect(x: 0, y: 0, width: buttonSingnin.frame.width, height: buttonSingnin.frame.height+50)
        buttonSingnin.layer.addSublayer(layerGradient)
        buttonSingnin.layer.cornerRadius = 5
    }

    @IBAction func updateUserName(){
        if username.text!.count == 0 {
            UIHelper.alertSimpleMessage(about: "请输入真实姓名", withDescription: "", in: self)
            return
        }
        weak var this = self;
        let progress = MBProgressHUD.showMessageNoHiden("", to: self.view)
        RequestHelper.post(atPath: "/kz/member/editrealname", withData: ["fullname":username.text!], withCompletion: { data in
            let json = JSON(data)
            let code = json["c"].intValue
            if code == 0{
                DispatchQueue.main.async {
                    progress.removeFromSuperview()
                    UIHelper.alertSimpleMessage(about: "更改姓名成功", withDescription: "", in: self)
                    this?.perform(#selector(this?.popcont), with: nil, afterDelay: 0.5)
                }
            }else{
                DispatchQueue.main.async {
                    progress.removeFromSuperview()
                    UIHelper.alertSimpleMessage(about: "更改失败", withDescription: json["m"].stringValue, in: self)
                }
            }
        },withError: {_ in 
            UIHelper.alertSimpleMessage(about: "服务器异常，\(getErrorString())", withDescription: "", in: self)
        })
    }
    @objc func popcont()  {
         self.navigationController?.popViewController(animated: true)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
